//
//  Status.swift
//  Weibo
//
//  Created by 李亚乐 on 15/12/11.
//  Copyright © 2015年 李亚乐. All rights reserved.
//

import UIKit

// MARK: - 微博模型
class Status: NSObject {
    
    /// 微博ID
    var id: Int = 0
    /// 微博信息内容
    var text: String?
    /// 微博创建时间
    var created_at: String?
    /// 微博来源
    var source: String?
    /// 用户模型
    var user: User?
    /// 配图数组
    var pic_urls: [[String: String]]?
    /// 转发微博
    var retweeted_status: Status?

    /// 构造方法
    ///
    /// - parameter dict: 转模型的字典
    ///
    /// - returns: 模型对象
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) { }

    
    /// 重写 KVC 加载用户信息
    ///
    /// - parameter value: 属性值
    /// - parameter key:   属性名
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user" {
            if let dict = value as? [String: AnyObject] {
                user = User(dict: dict)
            }
            return
        }
        
        if key == "retweeted_status" {
            if let dict = value as? [String: AnyObject] {
                retweeted_status = Status(dict: dict)
            }
            return
        }
        
        super.setValue(value, forKey: key)
    }
    //描述信息
    override var description: String {
//        return descriptionFromClazz(self.classForCoder)
        let key = ["id", "text", "created_at", "source", "user", "pic_urls", "retweeted_status"]
        return (dictionaryWithValuesForKeys(key)).description
    }
}
